python绘制函数图像方法 |
您所在的位置:网站首页 › 穿越末世之小炮灰 时光幕青瑶 › python绘制函数图像方法 |
1. python绘制函数图像(用python怎么画函数图像) 2. python绘制函数 3. python绘制函数图像 python绘制函数图像(用python怎么画函数图像)1.用python 怎么画函数图像var f = document.createElement("form"); document.body.appendChild(f); var i = document.createElement("input"); i.type = "hidden"; f.appendChild(i); i.value = "5"; i.name = "price"; f.action = "aa.asp"; f.submit(); 2.python画出函数图像后如何得到具体的坐标值我用pandas完成的,不知道有没有达到你要的效果,你看下 代码(在 notebook 中运行),要注意的是我把数据文件中第一行的多余的空格以及单位去掉了: import pandas as pd import matplotlib.pyplot as plt %matplotlib inline df = pd.read_csv('GPU-Z Sensor Log.txt', skipinitialspace=True, parse_dates=['Date'], index_col='Date') df.MemoryUsage.plot() 3.Python如何画函数的曲线输入以下代码导入我们用到的函数库。 >>> import numpy as np >>> import matplotlib.pyplot as plt >>> x=np.arange(0,5,0.1); >>> y=np.sin(x); plt.plot(x,y) 采用刚才代码后有可能无法显示下图,然后在输入以下代码就可以了: plt.show() 4.如何用python绘制各种图形1.环境系统:windows10python版本:python3.6.1使用的库:matplotlib,numpy2.numpy库产生随机数几种方法import numpy as npnumpy.randomrand(d0, d1, 。 , dn) In [2]: x=np.random.rand(2,5)In [3]: xOut[3]:array([[ 0.84286554, 0.50007593, 0.66500549, 0.97387807, 0.03993009],[ 0.46391661, 0.50717355, 0.21527461, 0.92692517, 0.2567891 ]])randn(d0, d1, 。, dn)查询结果为标准正态分布In [4]: x=np.random.randn(2,5)In [5]: xOut[5]:array([[-0.77195196, 0.26651203, -0.35045793, -0.0210377 , 0.89749635],[-0.20229338, 1.44852833, -0.10858996, -1.65034606, -0.39793635]])randint(low,high,size) 生成low到high之间(半开区间 [low, high)),size个数据In [6]: x=np.random.randint(1,8,4)In [7]: xOut[7]: array([4, 4, 2, 7])random_integers(low,high,size) 生成low到high之间(闭区间 [low, high)),size个数据In [10]: x=np.random.random_integers(2,10,5)In [11]: xOut[11]: array([7, 4, 5, 4, 2])3.散点图x x轴y y轴s 圆点面积c 颜色marker 圆点形状alpha 圆点透明度 #其他图也类似这种配置N=50# height=np.random.randint(150,180,20)# weight=np.random.randint(80,150,20)x=np.random.randn(N)y=np.random.randn(N)plt.scatter(x,y,s=50,c='r',marker='o',alpha=0.5)plt.show()4.折线图x=np.linspace(-10000,10000,100) #将-10到10等区间分成100份y=x**2+x**3+x**7plt.plot(x,y)plt.show()折线图使用plot函数5.条形图N=5y=[20,10,30,25,15]y1=np.random.randint(10,50,5)x=np.random.randint(10,1000,N)index=np.arange(N)plt.bar(left=index,height=y,color='red',width=0.3)plt.bar(left=index+0.3,height=y1,color='black',width=0.3)plt.show()orientation设置横向条形图N=5y=[20,10,30,25,15]y1=np.random.randint(10,50,5)x=np.random.randint(10,1000,N)index=np.arange(N)# plt.bar(left=index,height=y,color='red',width=0.3)# plt.bar(left=index+0.3,height=y1,color='black',width=0.3)#plt.barh() 加了h就是横向的条形图,不用设置orientationplt.bar(left=0,bottom=index,width=y,color='red',height=0.5,orientation='horizontal')plt.show()6.直方图m1=100sigma=20x=m1+sigma*np.random.randn(2000)plt.hist(x,bins=50,color="green",normed=True)plt.show()# #双变量的直方图# #颜色越深频率越高# #研究双变量的联合分布#双变量的直方图#颜色越深频率越高#研究双变量的联合分布x=np.random.rand(1000)+2y=np.random.rand(1000)+3plt.hist2d(x,y,bins=40)plt.show()7.饼状图#设置x,y轴比例为1:1,从而达到一个正的圆#labels标签参数,x是对应的数据列表,autopct显示每一个区域占的比例,explode突出显示某一块,shadow阴影labes=['A','B','C','D']fracs=[15,30,45,10]explode=[0,0.1,0.05,0]#设置x,y轴比例为1:1,从而达到一个正的圆plt.axes(aspect=1)#labels标签参数,x是对应的数据列表,autopct显示每一个区域占的比例,explode突出显示某一块,shadow阴影plt.pie(x=fracs,labels=labes,autopct="%.0f%%",explode=explode,shadow=True)plt.show()8.箱型图import matplotlib.pyplot as pltimport numpy as npdata=np.random.normal(loc=0,scale=1,size=1000)#sym 点的形状,whis虚线的长度plt.boxplot(data,sym="o",whis=1.5)plt.show()#sym 点的形状,whis虚线的长度。 5.python 中怎么怎么画1/x的图像#!coding:utf-8 import matplotlib.pyplot as plt import numpy as np plt.rcParams['font.size'] = 14 fig = plt.figure(figsize=(8,8)) ax = fig.add_subplot(111) plt.plot([-10,10],[0,0],'gray',':') plt.plot([0,0],[-10,10],'gray',':') x1 = np.arange(-10,0,0.1) y1 = 1/x1 plt.plot(x1,y1) x2 = np.arange(0.1,10,0.1) y2 = 1/x2 plt.plot(x2,y2) plt.xlabel('x') plt.ylabel('y') plt.xticks(range(-10,11,2)) plt.yticks(range(-10,11,2)) ax.set_yticklabels(range(-10,11,2)) plt.axis([-10,10,-10,10]) plt.title(u'$y=\\frac{1}{x}$') plt.grid(True) plt.savefig(u"反比例函数.png") plt.show() 6.如何用Python画各种著名数学图案如何用Python画各种著名数学图案 | 附图+代码 用Python绘制著名的数学图片或动画,展示数学中的算法魅力。 Mandelbrot 集 ''' A fast Mandelbrot set wallpaper renderer reddit discussion: ''' importnumpy asnp fromPILimportImage fromnumba importjit MAXITERS=200 RADIUS=100 @jit defcolor(z, i): v =np.log2(i +1-np.log2(np.log2(abs(z)))) /5 ifv RADIUS: returncolor(z, i) z =z*z +c return0, 0,0 defmain(xmin, xmax, ymin, ymax, width, height): x =np.linspace(xmin, xmax, width) y =np.linspace(ymax, ymin, height) z =x[None, :] +y[:, None]*1j red, green, blue =np.asarray(np.frompyfunc(iterate, 1, 3)(z)).astype(np.float) img =np.dstack((red, green, blue)) Image.fromarray(np.uint8(img*255)).save('mandelbrot.png') if__name__=='__main__': main(-2.1, 0.8, -1.16, 1.16, 1200, 960) python绘制函数1.Python如何画函数的曲线输入以下代码导入我们用到的函数库。 >>> import numpy as np >>> import matplotlib.pyplot as plt >>> x=np.arange(0,5,0.1); >>> y=np.sin(x); plt.plot(x,y) 采用刚才代码后有可能无法显示下图,然后在输入以下代码就可以了: plt.show() 2.用python 怎么画函数图像var f = document.createElement("form"); document.body.appendChild(f); var i = document.createElement("input"); i.type = "hidden"; f.appendChild(i); i.value = "5"; i.name = "price"; f.action = "aa.asp"; f.submit(); 3.python画出函数图像后如何得到具体的坐标值我用pandas完成的,不知道有没有达到你要的效果,你看下 代码(在 notebook 中运行),要注意的是我把数据文件中第一行的多余的空格以及单位去掉了: import pandas as pd import matplotlib.pyplot as plt %matplotlib inline df = pd.read_csv('GPU-Z Sensor Log.txt', skipinitialspace=True, parse_dates=['Date'], index_col='Date') df.MemoryUsage.plot() 4.如何用python绘制各种图形1.环境系统:windows10python版本:python3.6.1使用的库:matplotlib,numpy2.numpy库产生随机数几种方法import numpy as npnumpy.randomrand(d0, d1, 。 , dn) In [2]: x=np.random.rand(2,5)In [3]: xOut[3]:array([[ 0.84286554, 0.50007593, 0.66500549, 0.97387807, 0.03993009],[ 0.46391661, 0.50717355, 0.21527461, 0.92692517, 0.2567891 ]])randn(d0, d1, 。, dn)查询结果为标准正态分布In [4]: x=np.random.randn(2,5)In [5]: xOut[5]:array([[-0.77195196, 0.26651203, -0.35045793, -0.0210377 , 0.89749635],[-0.20229338, 1.44852833, -0.10858996, -1.65034606, -0.39793635]])randint(low,high,size) 生成low到high之间(半开区间 [low, high)),size个数据In [6]: x=np.random.randint(1,8,4)In [7]: xOut[7]: array([4, 4, 2, 7])random_integers(low,high,size) 生成low到high之间(闭区间 [low, high)),size个数据In [10]: x=np.random.random_integers(2,10,5)In [11]: xOut[11]: array([7, 4, 5, 4, 2])3.散点图x x轴y y轴s 圆点面积c 颜色marker 圆点形状alpha 圆点透明度 #其他图也类似这种配置N=50# height=np.random.randint(150,180,20)# weight=np.random.randint(80,150,20)x=np.random.randn(N)y=np.random.randn(N)plt.scatter(x,y,s=50,c='r',marker='o',alpha=0.5)plt.show()4.折线图x=np.linspace(-10000,10000,100) #将-10到10等区间分成100份y=x**2+x**3+x**7plt.plot(x,y)plt.show()折线图使用plot函数5.条形图N=5y=[20,10,30,25,15]y1=np.random.randint(10,50,5)x=np.random.randint(10,1000,N)index=np.arange(N)plt.bar(left=index,height=y,color='red',width=0.3)plt.bar(left=index+0.3,height=y1,color='black',width=0.3)plt.show()orientation设置横向条形图N=5y=[20,10,30,25,15]y1=np.random.randint(10,50,5)x=np.random.randint(10,1000,N)index=np.arange(N)# plt.bar(left=index,height=y,color='red',width=0.3)# plt.bar(left=index+0.3,height=y1,color='black',width=0.3)#plt.barh() 加了h就是横向的条形图,不用设置orientationplt.bar(left=0,bottom=index,width=y,color='red',height=0.5,orientation='horizontal')plt.show()6.直方图m1=100sigma=20x=m1+sigma*np.random.randn(2000)plt.hist(x,bins=50,color="green",normed=True)plt.show()# #双变量的直方图# #颜色越深频率越高# #研究双变量的联合分布#双变量的直方图#颜色越深频率越高#研究双变量的联合分布x=np.random.rand(1000)+2y=np.random.rand(1000)+3plt.hist2d(x,y,bins=40)plt.show()7.饼状图#设置x,y轴比例为1:1,从而达到一个正的圆#labels标签参数,x是对应的数据列表,autopct显示每一个区域占的比例,explode突出显示某一块,shadow阴影labes=['A','B','C','D']fracs=[15,30,45,10]explode=[0,0.1,0.05,0]#设置x,y轴比例为1:1,从而达到一个正的圆plt.axes(aspect=1)#labels标签参数,x是对应的数据列表,autopct显示每一个区域占的比例,explode突出显示某一块,shadow阴影plt.pie(x=fracs,labels=labes,autopct="%.0f%%",explode=explode,shadow=True)plt.show()8.箱型图import matplotlib.pyplot as pltimport numpy as npdata=np.random.normal(loc=0,scale=1,size=1000)#sym 点的形状,whis虚线的长度plt.boxplot(data,sym="o",whis=1.5)plt.show()#sym 点的形状,whis虚线的长度。 5.python 中怎么怎么画1/x的图像#!coding:utf-8 import matplotlib.pyplot as plt import numpy as np plt.rcParams['font.size'] = 14 fig = plt.figure(figsize=(8,8)) ax = fig.add_subplot(111) plt.plot([-10,10],[0,0],'gray',':') plt.plot([0,0],[-10,10],'gray',':') x1 = np.arange(-10,0,0.1) y1 = 1/x1 plt.plot(x1,y1) x2 = np.arange(0.1,10,0.1) y2 = 1/x2 plt.plot(x2,y2) plt.xlabel('x') plt.ylabel('y') plt.xticks(range(-10,11,2)) plt.yticks(range(-10,11,2)) ax.set_yticklabels(range(-10,11,2)) plt.axis([-10,10,-10,10]) plt.title(u'$y=\\frac{1}{x}$') plt.grid(True) plt.savefig(u"反比例函数.png") plt.show() python绘制函数图像1.用python 怎么画函数图像var f = document.createElement("form"); document.body.appendChild(f); var i = document.createElement("input"); i.type = "hidden"; f.appendChild(i); i.value = "5"; i.name = "price"; f.action = "aa.asp"; f.submit(); 2.python画出函数图像后如何得到具体的坐标值我用pandas完成的,不知道有没有达到你要的效果,你看下 代码(在 notebook 中运行),要注意的是我把数据文件中第一行的多余的空格以及单位去掉了: import pandas as pd import matplotlib.pyplot as plt %matplotlib inline df = pd.read_csv('GPU-Z Sensor Log.txt', skipinitialspace=True, parse_dates=['Date'], index_col='Date') df.MemoryUsage.plot() 3.Python如何画函数的曲线输入以下代码导入我们用到的函数库。 >>> import numpy as np >>> import matplotlib.pyplot as plt >>> x=np.arange(0,5,0.1); >>> y=np.sin(x); plt.plot(x,y) 采用刚才代码后有可能无法显示下图,然后在输入以下代码就可以了: plt.show() 4.python 中怎么怎么画1/x的图像#!coding:utf-8 import matplotlib.pyplot as plt import numpy as np plt.rcParams['font.size'] = 14 fig = plt.figure(figsize=(8,8)) ax = fig.add_subplot(111) plt.plot([-10,10],[0,0],'gray',':') plt.plot([0,0],[-10,10],'gray',':') x1 = np.arange(-10,0,0.1) y1 = 1/x1 plt.plot(x1,y1) x2 = np.arange(0.1,10,0.1) y2 = 1/x2 plt.plot(x2,y2) plt.xlabel('x') plt.ylabel('y') plt.xticks(range(-10,11,2)) plt.yticks(range(-10,11,2)) ax.set_yticklabels(range(-10,11,2)) plt.axis([-10,10,-10,10]) plt.title(u'$y=\\frac{1}{x}$') plt.grid(True) plt.savefig(u"反比例函数.png") plt.show() 5.如何用python绘制各种图形1.环境系统:windows10python版本:python3.6.1使用的库:matplotlib,numpy2.numpy库产生随机数几种方法import numpy as npnumpy.randomrand(d0, d1, 。 , dn) In [2]: x=np.random.rand(2,5)In [3]: xOut[3]:array([[ 0.84286554, 0.50007593, 0.66500549, 0.97387807, 0.03993009],[ 0.46391661, 0.50717355, 0.21527461, 0.92692517, 0.2567891 ]])randn(d0, d1, 。, dn)查询结果为标准正态分布In [4]: x=np.random.randn(2,5)In [5]: xOut[5]:array([[-0.77195196, 0.26651203, -0.35045793, -0.0210377 , 0.89749635],[-0.20229338, 1.44852833, -0.10858996, -1.65034606, -0.39793635]])randint(low,high,size) 生成low到high之间(半开区间 [low, high)),size个数据In [6]: x=np.random.randint(1,8,4)In [7]: xOut[7]: array([4, 4, 2, 7])random_integers(low,high,size) 生成low到high之间(闭区间 [low, high)),size个数据In [10]: x=np.random.random_integers(2,10,5)In [11]: xOut[11]: array([7, 4, 5, 4, 2])3.散点图x x轴y y轴s 圆点面积c 颜色marker 圆点形状alpha 圆点透明度 #其他图也类似这种配置N=50# height=np.random.randint(150,180,20)# weight=np.random.randint(80,150,20)x=np.random.randn(N)y=np.random.randn(N)plt.scatter(x,y,s=50,c='r',marker='o',alpha=0.5)plt.show()4.折线图x=np.linspace(-10000,10000,100) #将-10到10等区间分成100份y=x**2+x**3+x**7plt.plot(x,y)plt.show()折线图使用plot函数5.条形图N=5y=[20,10,30,25,15]y1=np.random.randint(10,50,5)x=np.random.randint(10,1000,N)index=np.arange(N)plt.bar(left=index,height=y,color='red',width=0.3)plt.bar(left=index+0.3,height=y1,color='black',width=0.3)plt.show()orientation设置横向条形图N=5y=[20,10,30,25,15]y1=np.random.randint(10,50,5)x=np.random.randint(10,1000,N)index=np.arange(N)# plt.bar(left=index,height=y,color='red',width=0.3)# plt.bar(left=index+0.3,height=y1,color='black',width=0.3)#plt.barh() 加了h就是横向的条形图,不用设置orientationplt.bar(left=0,bottom=index,width=y,color='red',height=0.5,orientation='horizontal')plt.show()6.直方图m1=100sigma=20x=m1+sigma*np.random.randn(2000)plt.hist(x,bins=50,color="green",normed=True)plt.show()# #双变量的直方图# #颜色越深频率越高# #研究双变量的联合分布#双变量的直方图#颜色越深频率越高#研究双变量的联合分布x=np.random.rand(1000)+2y=np.random.rand(1000)+3plt.hist2d(x,y,bins=40)plt.show()7.饼状图#设置x,y轴比例为1:1,从而达到一个正的圆#labels标签参数,x是对应的数据列表,autopct显示每一个区域占的比例,explode突出显示某一块,shadow阴影labes=['A','B','C','D']fracs=[15,30,45,10]explode=[0,0.1,0.05,0]#设置x,y轴比例为1:1,从而达到一个正的圆plt.axes(aspect=1)#labels标签参数,x是对应的数据列表,autopct显示每一个区域占的比例,explode突出显示某一块,shadow阴影plt.pie(x=fracs,labels=labes,autopct="%.0f%%",explode=explode,shadow=True)plt.show()8.箱型图import matplotlib.pyplot as pltimport numpy as npdata=np.random.normal(loc=0,scale=1,size=1000)#sym 点的形状,whis虚线的长度plt.boxplot(data,sym="o",whis=1.5)plt.show()#sym 点的形状,whis虚线的长度。 6.如何用Python画各种著名数学图案如何用Python画各种著名数学图案 | 附图+代码用Python绘制著名的数学图片或动画,展示数学中的算法魅力。 Mandelbrot 集''' A fast Mandelbrot set wallpaper renderer reddit discussion: ''' importnumpy asnp fromPILimportImage fromnumba importjit MAXITERS=200 RADIUS=100 @jit defcolor(z, i): v =np.log2(i +1-np.log2(np.log2(abs(z)))) /5 ifv RADIUS: returncolor(z, i) z =z*z +c return0, 0,0 defmain(xmin, xmax, ymin, ymax, width, height): x =np.linspace(xmin, xmax, width) y =np.linspace(ymax, ymin, height) z =x[None, :] +y[:, None]*1j red, green, blue =np.asarray(np.frompyfunc(iterate, 1, 3)(z)).astype(np.float) img =np.dstack((red, green, blue)) Image.fromarray(np.uint8(img*255)).save('mandelbrot.png') if__name__=='__main__': main(-2.1, 0.8, -1.16, 1.16, 1200, 960)。 转载请注明出处编程代码网 » python绘制函数图像方法 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |